package com.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.dao.AdminDao;
import com.pojo.AdminPojo;
import com.util.Log;


public class DeleteAdminInfo extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException{
		response.setContentType("text/html");
		response.setCharacterEncoding("UTF-8");
		PrintWriter out = response.getWriter();
		
		HttpSession session = request.getSession(true);
		String name = request.getParameter("name");
		
		String message = "";
		if (name.equals("")){
			message = "请选择要删除的账号！";
		}  else {
			message = "删除失败!";
			if(name.equals(session.getAttribute("curradmin"))) {
				message = "不能删除自己的账号!";
			}else{
				String swhere = " where name='"+name+"'";
				AdminDao dao = new AdminDao();
				if(dao.delAdmin(swhere)==0) message="删除成功";
				dao.closeAll();
			}
		}
		String json = "{\"status\":\""+message+"\"}";
		Log.write(json);
		out.println(json);
		out.flush();
        out.close();
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request, response);
	}

}
